package com.android.entities;

import org.json.JSONException;
import org.json.JSONObject;

public class Event {
	
	private String id;
	private String name;
	private String description;
	private String category;
	
	//*************//
	//Constructors//
	//***********//
	public Event() {
		
	}
	
	public Event(JSONObject data) {
		try {
			if (data.has("eventKey") && data.getString("eventKey") != null)
				id = data.getString("eventKey");
			if (data.has("eventName") && data.getString("eventName") != null)
				name = data.getString("eventName");
			if (data.has("description") && data.getString("description") != null)
				description = data.getString("description");
			if (data.has("eventCategory") && data.getString("eventCategory") != null)
				category = data.getString("eventCategory");

		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	//***************//
	//Public Methods//
	//*************//

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		String value = this.description; 
		return value;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public JSONObject toJSON() {
		JSONObject event = new JSONObject();
		
		AddIfNotNull(event, "eventKey", id);
		AddIfNotNull(event, "eventName", name);
		AddIfNotNull(event, "eventCategory", category);
		AddIfNotNull(event, "description", description);
		
		return event;
	}

	private void AddIfNotNull(JSONObject j, String key, Object o) {
		try {
			if (o != null)
				j.put(key, o);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}